/*
@(#)RoleController   2024-11-09
 
Copyright (c) 2011-2024 杭州湖畔网络技术有限公司 
保留所有权利 
本软件为杭州湖畔网络技术有限公司所有及包含机密信息，须遵守其相关许可证条款进行使用。
Copyright (c) 2011-2024 HUPUN Network Technology CO.,LTD.
All rights reserved.
This software is the confidential and proprietary information of HUPUN
Network Technology CO.,LTD("Confidential Information").  You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into with HUPUN.
Website：http://www.hupun.com
*/
package org.obp.upms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.obp.core.result.ApiResult;
import org.obp.data.result.PageResult;
import org.obp.data.support.QueryResolver;
import org.obp.upms.model.WorkRoleDO;
import org.obp.upms.query.WorkRoleQuery;
import org.obp.upms.service.WorkRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Jackey 2024/11/9
 */
@RestController
@RequestMapping("/v1/work/role")
@Api(tags = {"角色接口"})
public class RoleController {

    @Autowired
    private WorkRoleService workRoleService;

    @ApiOperation("角色分页列表")
    @PostMapping("/pager")
    public ApiResult<PageResult<WorkRoleDO>> rolePager(@RequestBody WorkRoleQuery query) {
        IPage pageParam = query.pageParam();
        QueryWrapper<WorkRoleDO> queryWrapper = QueryResolver.buildQuery(query);
        queryWrapper.lambda().orderByDesc(WorkRoleDO::getGmtCreated);
        IPage<WorkRoleDO> pageDO = workRoleService.page(pageParam, queryWrapper);
        PageResult<WorkRoleDO> pageResultDO = new PageResult<>(pageDO);
        return ApiResult.ok(pageResultDO);
    }

    @ApiOperation("角色下拉列表")
    @GetMapping("/list")
    public ApiResult<List<WorkRoleDO>> roleList() {
        return ApiResult.ok(workRoleService.list());
    }

    @ApiOperation("角色新增功能")
    @PostMapping("/insert")
    public ApiResult<WorkRoleDO> roleInsert(@Validated @RequestBody WorkRoleDO role) {
        workRoleService.save(role);
        return ApiResult.ok(role);
    }

    @ApiOperation("角色更新功能")
    @PostMapping("/update")
    public ApiResult<String> roleUpdate(@Validated @RequestBody WorkRoleDO role) {
        workRoleService.updateById(role);
        return ApiResult.ok();
    }

    @ApiOperation("角色删除功能")
    @GetMapping("/delete")
    public ApiResult<String> roleDelete(@RequestParam String id) {
        workRoleService.deleteById(id);
        return ApiResult.ok();
    }

}